
    
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">修改密码</h4>
                    </div>
                    <form class="form-horizontal m-t" id="myForm">
                        <div class="modal-body">
                            <!--错误信息提示-->
                            <div id="errormessage" class="alert alert-danger text-center" style="display:none">&nbsp;</div>
                            
                            <div class="form-group">
                                <label class="col-sm-3 control-label">原始密码</label>
                                <div class="col-sm-8">
                                    <input id="oldpassword" name="oldpassword" class="form-control" type="password" placeholder="原始密码">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">密码</label>
                                <div class="col-sm-8">
                                    <input id="password" name="password" class="form-control" type="password" placeholder="登录密码">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">确认密码</label>
                                <div class="col-sm-8">
                                    <input id="password2" name="password2" class="form-control" type="password" placeholder="再次输入登录密码">
                                </div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-white" data-dismiss="modal" >关闭</button>
                            <button type="submit" class="btn btn-primary">保存</button>
                        </div>
                        </form>


    
    <script>
    
        $(document).ready(function() {

            $("#myForm").validate({
                rules: {
                    oldpassword : {
                        required : true,
                        minlength : 2,
                        remote: {
                            url: "/myuser/checkpassword",
                            type: "post",
                            data: {
                                oldpassword: function() {
                                    return $('#myForm :input[name="oldpassword"]').val();
                                }
                            }
                        }
                    },
                    password : {
                        required : true,
                        minlength : 5
                    },
                    password2 : {
                        required : true,
                        minlength : 5,
                        equalTo : "#password"
                    },
                },
                
                submitHandler: function(form) {  //通过之后回调
                    var data = $(form).serialize();
                     $.ajax({ 
                        url : "/myuser/userchangepassword", 
                        type : "post", 
                        dataType : "json", 
                        data: data, 
                        success : function(d) { 
                            if (d.status==200){
                                $("#modalpassword").modal('hide');
                                swal({
                                    title: "操作成功",
                                    text: "2秒自动关闭",
                                    timer: 2000,
                                    type: "success",
                                    confirmButtonColor: "#DD6B55",
                                    confirmButtonText: "确定",
                                });
                            }else{
                                $("#errormessage").show().html("<h4>" + d.msg + "</h4>");
                            }
                        } 
                    }); 
                }, 
                invalidHandler: function(form, validator) {  //不通过回调 
                       return false; 
                } 
            });
            
        });
    </script>

